import axios from 'axios'

export const SupplierService = class SupplierService {
    static supplierService = null
    requestUrl = '/supplier/suppliers'

    static getInstance() {
        if (this.supplierService == null) {
            this.supplierService = new SupplierService()
        }
        return this.supplierService
    }

    /**
     * 分页查询
     * @param params
     */
    pageQuery(params) {
        return axios.get(`${this.requestUrl}/page`, {
            params
        })
    }

    /**
     * 根据id删除
     * @param ids
     */
    removeByIds(ids) {
        return axios.delete(`${this.requestUrl}/${ids.join(',')}`)
    }

    /**
     * 查询列表
     * @param params
     * @returns {Promise<AxiosResponse<T>>}
     */
    list(params) {
        return axios.get(this.requestUrl, {
            params
        })
    }

    /**
     * 根据id查询
     * @param id
     */
    queryById(id) {
        return axios.get(`${this.requestUrl}/${id}`)
    }

    /**
     * 添加修改
     * @param object
     */
    saveOrUpdate(object) {
        return axios({
            url: `/supplier/suppliers`,
            method: `${!object.sid ? 'post' : 'put'}`,
            data: object
        })
    }
}
